home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 25
/
AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso
/
PublicDomain
/
Spiele
/
TextElite
/
Original
/
txtelite.c
< prev
Wrap
C/C++ Source or Header
|
2000-02-26
|
20KB
|
741 lines
/* txtelite.c */
/* Textual version of Elite trading (C implementation) */
/* Converted by Ian Bell from 6502 Elite sources.
Original 6502 Elite by Ian Bell & David Braben. */
/* ----------------------------------------------------------------------
The nature of basic mechanisms used to generate the Elite socio-economic
universe are now widely known. A competant games programmer should be able to
produce equivalent functionality. A competant hacker should be able to lift
the exact system from the object code base of official conversions.
This file may be regarded as defining the Classic Elite universe.
It contains a C implementation of the precise 6502 algorithms used in the
original BBC Micro version of Acornsoft Elite together with a parsed textual
command testbed.
Note that this is not the universe of David Braben's 'Frontier' series.
ICGB 13/10/99
iancgbell@email.com
www.ibell.co.uk
---------------------------------------------------------------------- */
/* Note that this program is "quick-hack" text parser-driven version
of Elite with no combat or missions.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#if 0
#include <conio.h>
#include <graph.h>
#include <malloc.h>
#endif
#define true (-1)
#define false (0)
#define tonnes (0)
#define maxlen (20) /* Length of strings */
typedef int boolean;
typedef unsigned short uint16;
typedef signed short int16;
typedef signed long int32;
typedef uint16 uint;
typedef int planetnum;
typedef struct
{ uint16 w0;
uint16 w1;
uint16 w2;
} seedtype; /* six byte random number used as seed for planets */
typedef struct
{ uint x;
uint y; /* One byte unsigned */
uint economy; /* These two are actually only 0-7 */
uint govtype;
uint techlev; /* 0-16 i think */
uint population; /* One byte */
uint productivity; /* Two byte */
uint radius; /* Two byte (not used by game at all) */
char name[12];
} plansys ;
#define galsize (256)
#define AlienItems (16)
#define lasttrade AlienItems
#define numforLave 7 /* Lave is 7th generated planet in galaxy one */
#define numforZaonce 129
#define numforDiso 147
#define numforRied 46
plansys galaxy[galsize]; /* Need 0 to galsize-1 inclusive */
seedtype seed;
typedef struct
{ /* In 6502 version these were: */
uint baseprice; /* one byte */
int16 gradient; /* five bits plus sign */
uint basequant; /* one byte */
uint maskbyte; /* one byte */
uint units; /* two bits */
char name[20]; /* longest="Radioactives" */
} tradegood ;
typedef struct
{ uint quantity[lasttrade+1];
uint price[lasttrade+1];
} markettype ;
/* Player workspace */
uint shipshold[lasttrade+1]; /* Contents of cargo bay */
planetnum currentplanet; /* Current planet */
uint galaxynum; /* Galaxy number (1-8) */
int32 cash;
uint fuel;
markettype localmarket;
uint holdspace;
int fuelcost =2; /* 0.2 CR/Light year */
int maxfuel =70; /* 7.0 LY tank */
const uint16 base0=0x5A4A;
const uint16 base1=0x0248;
const uint16 base2=0xB753; /* Base seed for galaxy 1 */
char pairs[] = "..LEXEGEZACEBISO"
"USESARMAINDIREA."
"ERATENBERALAVETI"
"EDORQUANTEISRION"; /* Dots should be nullprint characters */
char govnames[][maxlen]={"Anarchy","Feudal","Multi-gov","Dictatorship",
"Communist","Confederacy","Democracy","Corporate State"};
char econnames[][maxlen]={"Rich Ind","Average Ind","Poor Ind","Mainly Ind",
"Mainly Agri","Rich Agri","Average Agri","Poor Agri"};
char unitnames[][5] ={"t","kg","g"};
/* Data for DB's price/availability generation system */
/* Base Grad Base Mask Un Name
price ient quant it */
#define POLITICALLY_CORRECT 0
/* Set to 1 for NES-sanitised trade goods */
tradegood commodities[]=
{
{0x13,-0x02,0x06,0x01,0,"Food "},
{0x14,-0x01,0x0A,0x03,0,"Textiles "},
{0x41,-0x03,0x02,0x07,0,"Radioactives"},
#if POLITICALLY_CORRECT
{0x28,-0x05,0xE2,0x1F,0,"Robot Slaves"},
{0x53,-0x05,0xFB,0x0F,0,"Beverages "},
#else
{0x28,-0x05,0xE2,0x1F,0,"Slaves "},
{0x53,-0x05,0xFB,0x0F,0,"Liquor/Wines"},
#endif
{0xC4,+0x08,0x36,0x03,0,"Luxuries "},
#if POLITICALLY_CORRECT
{0xEB,+0x1D,0x08,0x78,0,"Rare Species"},
#else
{0xEB,+0x1D,0x08,0x78,0,"Narcotics "},
#endif
{0x9A,+0x0E,0x38,0x03,0,"Computers "},
{0x75,+0x06,0x28,0x07,0,"Machinery "},
{0x4E,+0x01,0x11,0x1F,0,"Alloys "},
{0x7C,+0x0d,0x1D,0x07,0,"Firearms "},
{0xB0,-0x09,0xDC,0x3F,0,"Furs "},
{0x20,-0x01,0x35,0x03,0,"Minerals "},
{0x61,-0x01,0x42,0x07,1,"Gold "},
{0xAB,-0x02,0x37,0x1F,1,"Platinum "},
{0x2D,-0x01,0xFA,0x0F,2,"Gem-Strones "},
{0x35,+0x0F,0xC0,0x07,0,"Alien Items "},
};
/**-Required data for text interface **/
char tradnames[lasttrade][maxlen]; /* Tradegood names used in text commands
Set using commodities array */
#define nocomms 13
boolean dobuy(char *);
boolean dosell(char *);
boolean dofuel(char *);
boolean dojump(char *);
boolean docash(char *);
boolean domkt(char *);
boolean dohelp(char *);
boolean dohold(char *);
boolean dosneak(char *);
boolean dolocal(char *);
boolean doinfo(char *);
boolean dogalhyp(char *);
boolean doquit(char *);
char commands[nocomms][maxlen]=
{"buy", "sell", "fuel", "jump",
"cash", "mkt", "help", "hold",
"sneak", "local", "info", "galhyp",
"quit"
};
boolean (*comfuncs[nocomms])(char *)=
{dobuy, dosell, dofuel, dojump,
docash, domkt, dohelp, dohold,
dosneak, dolocal, doinfo, dogalhyp,
doquit
};
/**- General functions **/
char randbyte(void) { return (char)(rand()&0xFF);}
uint mymin(uint a,uint b) { if(a<b) return(a); else return(b);}
void stop(char * string)
{ printf("\n%s",string);
exit(1);
}
/**+ ftoi **/
signed int ftoi(double value)
{ return ((signed int)floor(value+0.5));
}
/**+ ftoi2 **/
signed int ftoi2(double value)
{ return ((signed int)floor(value));
}
void tweakseed(seedtype *s)
{ uint16 temp;
temp = ((*s).w0)+((*s).w1)+((*s).w2); /* 2 byte aritmetic */
(*s).w0 = (*s).w1;
(*s).w1 = (*s).w2;
(*s).w2 = temp;
}
/**-String functions for text interface **/
void stripout(char *s,const char c) /* Remove all c's from string s */
{ size_t i=0,j=0;
while(i<strlen(s))
{ if(s[i]!=c) { s[j]=s[i]; j++;}
i++;
}
s[j]=0;
}
int toupper(char c)
{ if((c>='a')&&(c<='z')) return(c+'A'-'a');
return((int)c);
}
int stringbeg(char *s,char *t)
/* Return nonzero iff string t begins with string s */
{ size_t i=0;
size_t l=strlen(s);
while((i<l)&(toupper(s[i])==toupper(t[i]))) i++;
if(i==l) return true; else return false;
}
uint stringmatch(char *s,char a[][20],uint n)
/* Check string s against n options in string array a
If matches ith element return i+1 else return 0 */
{ uint i=0;
while(i<n)
{ if(stringbeg(s,a[i])) return i+1;
i++;
}
return 0;
}
void spacesplit(char *s,char *t)
/* Split string s at first space, returning first 'word' in t & shortening s
*/
{ size_t i=0,j=0;
size_t l=strlen(s);
while((i<l)&(s[i]==' ')) i++;; /* Strip leading spaces */
if(i==l) {s[0]=0; t[0]=0; return;};
while((i<l)&(s[i]!=' ')) t[j++]=s[i++];
t[j]=0; i++; j=0;
while(i<l) s[j++]=s[i++];
s[j]=0;
}
/**-Functions for stock market **/
uint gamebuy(uint i, uint a)
/* Try to buy ammount a of good i Return ammount bought */
/* Cannot buy more than is availble, can afford, or will fit in hold */
{ ui